<template>
  <div class="app-container" ref="appcontainer">
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleLook"
          >查看修改会员卡价格</el-button
        >
      </el-col>
    </el-row> -->
    <el-table v-loading="loading" :height="tableHeight" :data="list">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="头像" align="center" prop="headImg" >
        <template slot-scope="scope">
            <img :src="scope.row.headImg" class="feadimg">
        </template>
      </el-table-column>
      <el-table-column label="用户名" align="center" prop="nickName" />
      <el-table-column label="联系方式" align="center" prop="phone" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      title="会员卡价格"
      :visible.sync="dialogVisible"
      width="400px"
    >
    <el-input type="number" v-model="price" class="priceinput" ></el-input>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleFix">确 定</el-button>
        <el-button @click="handelCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getUserList,getUserVipPrice,fixPrice } from "@/api/vip/index";
export default {
  data() {
    return {
      tableHeight: 0,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      loading: false,
      list: [],
      dialogVisible: false,
      price: 0
    };
  },
  methods: {
    calHeight() {
      this.$nextTick(() => {
        const rect = this.$refs.appcontainer.getBoundingClientRect();
        this.tableHeight = rect.height - 80;
      });
    },
    getList() {
        this.loading = true
      getUserList(this.queryParams).then((res) => {
        this.list = res.rows
        this.total = res.total
      }).finally(() => {
        this.loading = false
      })
    },
    handleLook() {
        this.dialogVisible = true
        this.getPrice()
    },
    getPrice() {
        getUserVipPrice().then(res => {
            this.price = res.price
        })
    },
    handelCancel() {
        this.price = 0
        this.dialogVisible = false
    },
    handleFix() {
        const data = {
            newPrice: parseFloat(this.price)
        }
        fixPrice(data).then(() => {
            this.msgSuccess("修改成功");
        })
    }
  },
  mounted() {
    this.calHeight();
    this.getList();
  },
};
</script>
<style scoped>
.feadimg {
    width: 50px;
    height: 50px;
}
.priceinput {
    width: 180px;
}
</style>